<?php

namespace App\Http\Controllers;

use App\Service\MemberPraiseService;
use App\Validation\MemberPraiseValidation;
use App\Validation\DeleteValidation;

class MemberPraiseController extends BaseController
{
	/**
	 * [doAction 点赞/点踩/取消点赞/取消点踩]
	 * @param  [type] $raw->memebr_id [会员id]
	 * @param  [type] $raw->t         [数据表id]
	 * @param  [type] $raw->tid       [数据列id]
	 * @param  [type] $raw->praise    [1、点赞 -1、点踩]
	 * @return [type] [description]
	 */
	public function doAction()
	{
		$this->getUser();
		$raw = $this->validation(new MemberPraiseValidation, $this->request->getJsonRawBody());

		$data = MemberPraiseService::do($raw);

		return $this->echoJson('ok');
	}

	/**
	 * [sumAction 点赞数量]
	 * @return [type] [description]
	 * @param  [type] $raw->t         [数据表id]
	 * @param  [type] $raw->tid       [数据列id]
	 */
	public function sumAction()
	{
		$this->getUser(0);
		$raw = $this->validation(new MemberPraiseValidation, $this->request->getJsonRawBody());

		$info = MemberPraiseService::juge($raw);
		$data = MemberPraiseService::sum($raw);

		$assign = [
			"total" 	=> $data,
			"is_praise" => $info
		];
		
		return $this->echoJson($assign);
	}
}